/*
 * Copyright @ 2024 weili23
 * com.sky.controller.user 15:50
 * All right reserved.
 */

package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @desc: 购物车
 * @author: weili23
 * @createTime: 2024/11/7 15:50
 * @version: v1.0
 */
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api(tags = "用户购物车相关接口")
@RestController
public class ShoppingCardController {

    @Resource
    private ShoppingCardService shoppingCardService;
    @ApiOperation("添加购物车")
    @PostMapping("/add")
    public Result addShoppingCard(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCardService.addShoppingCard(shoppingCartDTO);
        return Result.success();
    }

    @ApiOperation("查看购物车")
    @GetMapping("/list")
    public Result<List<ShoppingCart>> getShoppingCardList(){
        List<ShoppingCart> shoppingCarts = shoppingCardService.getShoppingCardList();
        return Result.success(shoppingCarts);
    }

    @ApiOperation("扣减购物车的一个商品")
    @PostMapping("/sub")
    public Result subShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCardService.subShoppingCart(shoppingCartDTO);
        return Result.success();
    }
    @ApiOperation("清空购物车")
    @DeleteMapping("/clean")
    public Result cleanShoppingCart(){
        shoppingCardService.cleanShoppingCart();
        return Result.success();
    }
}
